<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>
<button>send</button>
<button>取消</button>
</body>
<script>
	const btns = document.querySelectorAll("button");
	let xhr = null;
	btns[0].onclick = function(){
		if(xhr) xhr.abort();
		xhr = new XMLHttpRequest();
		xhr.open("get","/weibo");
		xhr.send();
		xhr.onload = function(){
			xhr = null;
			console.log(xhr.response);
		}
		xhr.onabort = function(){
			console.log("当用户取消请求时执行！");
		}
	}
	btns[1].onclick = function(){
		if(xhr) xhr.abort();
	}

</script>
</html>